$.extend({
    getType(e) {
        const myChart = echarts.init(e, null);
        myChart.showLoading()

        $.get('/result/get/byType', function (result) {
            myChart.hideLoading()
            const data = handle(result.payload)

            let option = {
                title: {
                    text: '同类型成果数目统计图',
                    subtext: '测试数据',
                    left: 'center'
                },
                toolbox: {
                    feature: {
                        saveAsImage: {},
                        restore: {}
                    }
                },
                tooltip: {
                    trigger: 'item',
                    formatter: '{a} <br/>{b} : {c} ({d}%)'
                },
                legend: {
                    type: 'scroll',
                    orient: 'vertical',
                    right: 10,
                    top: 45,
                    bottom: 20,
                    data: data.legendData,
                },
                series: [
                    {
                        name: '类型名',
                        type: 'pie',
                        radius: '55%',
                        center: ['50%', '50%'],
                        data: data.seriesData,
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0, 0, 0, 0.5)'
                            }
                        }
                    }
                ]
            };
            myChart.setOption(option)
        })

        function handle(data) {
            let legendData = [];
            let seriesData = [];
            data.map(t => {
                legendData.push(t[0])
                seriesData.push({
                    name: t[0],
                    value: t[1]
                })
            })
            return {
                legendData: legendData,
                seriesData: seriesData
            }
        }
    }
})